package com.example.mybatisplus.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.mybatisplus.common.utls.SessionUtils;
import com.example.mybatisplus.model.domain.FavouriteMovie;
import com.example.mybatisplus.model.domain.User;
import com.example.mybatisplus.mapper.UserMapper;
import com.example.mybatisplus.model.domain.WhitelistSetting;
import com.example.mybatisplus.service.UserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author fmx
 * @since 2024-11-10
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public User login(User user) {
        QueryWrapper<User> wrapper = new QueryWrapper<>();
        wrapper.eq("user_name",user.getUserName())
                .eq("user_password",user.getUserPassword());
        User one =baseMapper.selectOne(wrapper);// 这个base就是白名单mapper 故可以不注入
        // 登录时把登录用户存到session
        if(one != null){
            SessionUtils.saveCurrentUser(one);
        }
        return one;
    }

   /* @Override
    public User add(User user) {
        userMapp
    }*/

    @Override
    public Boolean getByUserName(User user) {
        QueryWrapper<User> wrapper = new QueryWrapper<>();
        wrapper.eq("user_name",user.getUserName());
        User one =baseMapper.selectOne(wrapper);// 这个base就是白名单mapper 故可以不注入
        if(one!=null){return true;}
        else return false;
    }

    @Override
    public Boolean addUser(User user) {
        return userMapper.insertUser(user);
    }

}
